﻿using System.Web.Mvc;

namespace RiderShop.WebSite.View.App_Start
{
    public class FilterConfig
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {

            filters.Add(new CustomeFilterAttribute());

            filters.Add(new HandleErrorAttribute());
        }
    }



    public class CustomeFilterAttribute : HandleErrorAttribute
    {

        public override void OnException(ExceptionContext filterContext)
        {

            //出错时间    

            string ErrTime = System.DateTime.Now.ToString();

            //错误类型       

            string ErrType = filterContext.Exception.GetType().ToString();

            //错误信息       

            string ErrMessage = filterContext.Exception.Message;

            //引发异常的方法   

            string targetsite = filterContext.Exception.TargetSite.ToString();

            //引发异常的对象     

            string source = filterContext.Exception.Source.ToString();

            //异常Controller名称       

            string controller = filterContext.RouteData.Values["controller"].ToString();

            //异常Action名称       

            string action = filterContext.RouteData.Values["action"].ToString();

            string ErrStr = string.Format("时间:{0} ,错误类型:{0},错误信息:{2},异常的方法:{3},异常的对象:{4},Controller名称:{5},Action名称:{6}", ErrTime, ErrType, ErrMessage, targetsite, source, controller, action);

            //Kevin.Comm.Logger.Tracer.TraceLog("Common Error:" + ErrStr, "Exception", "Exception", false);

        }


    }


}